import cv2
import numpy as np

def fuse_imgs(img_sf, img_lf, T12):
    h, w = img_sf.shape[:2]
    aligned_img_lf = cv2.warpPerspective(img_lf, T12, (w, h))
    fused_img = cv2.addWeighted(img_sf, 0.5, aligned_img_lf, 0.5, 0)
    return fused_img
    
    
    
if __name__ == '__main__':
    
    img_lf = cv2.imread("C:\\Users\\12590\\Desktop\\img_lf.bmp")
    img_sf = cv2.imread("C:\\Users\\12590\\Desktop\\img_sf.bmp")
    import time
    t1 = time.time()
    img_sf = cv2.resize(img_sf, (7926, 9474), interpolation=cv2.INTER_LINEAR)
    H = np.array([
        [1.22, 0.09, 447.57],
        [0.13, 1.14, 378.47],
        [0, 0, 1]
    ])
    img_fused = fuse_imgs(img_lf, img_sf, H)
    t2 = time.time()
    print(f"耗时:{t2-t1}")
    print(f"shape:{img_fused.shape}")
    cv2.namedWindow("img_fused", 0)
    cv2.resizeWindow("img_fused", 1920, 1080)
    cv2.imshow("img_fused", img_fused)
    cv2.waitKey(0)